package com.red.wood.module.system.web;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.red.wood.module.system.service.CitiesService;
import com.red.wood.module.system.service.ProvinceService;

@Controller
@RequestMapping("/cities")
public class CitiesController {

private static final Log log = LogFactory.getLog(CitiesController.class);
	
	@Autowired
	private CitiesService ciesService;
	@Autowired
	private ProvinceService provinceService;
	
	@RequestMapping(value = "getByProvinceid", method = RequestMethod.POST)
	@ResponseBody
	public List<Map<String, Object>> getByProvinceid(String provinceid){
		List<Map<String, Object>> list = new ArrayList<>(); 
		try{
			list = ciesService.getByProvinceid(provinceid);
		}catch(Exception e){
			log.error(e.getMessage(),e);
		}
		return list;
	}
	
	@RequestMapping(value = "getByProvince", method = RequestMethod.POST)
	@ResponseBody
	public List<Map<String, Object>> getByProvince(String province){
		List<Map<String, Object>> list = new ArrayList<>(); 
		try{
			Map<String, Object> provinceMap = provinceService.getByProvince(province);
			if(null != provinceMap){
				list = ciesService.getByProvinceid(provinceMap.get("provinceid").toString());
			}
		}catch(Exception e){
			log.error(e.getMessage(),e);
		}
		return list;
	}
}
